<?php

namespace app\model;

use think\Model;

class Customer extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'customer';


    function CustomerGenjin()
    {
        return $this->hasOne(\app\model\CustomerGenjin::class, 'id', 'cid');
    }
    public static function getField()
    {
        foreach (CustomerField::getsysField() as $vo) {
            $data[$vo['fieldsmingcheng']] = $vo['viewmingcheng'];
        }

        return $data;
    }


    public static function getcount($where)
    {
        $query = self::where($where);

        $getdata['date_start'] = date("Y-m-d H:i:s", strtotime("-1 day"));

        $getdata['date_end'] = date("Y-m-d H:i:s");

        if (!empty($getdata['date_start'])) {
            $query->andWhere('jieduan_time','>=', strtotime(trim($getdata['date_start'])));
        }
        if (!empty($getdata['date_end'])) {
            $query->andWhere('jieduan_time','<=', strtotime(trim($getdata['date_end'])) + 86400);
        }

        return $query->count();
    }

    public static function getusername($id)
    {
        $user = self::find($id);
        return $user->mingcheng;
    }
}
